﻿using System;
using System.IO;
using System.Text.Encodings.Web;
using ZYing.LiquidThemeEngine.FileProviders;

namespace ZYing.LiquidThemeEngine
{
    public class LiquidThemeEngineOptions
    {
        private ILiquidThemeFileProvider _fileProvider = NullLiquidThemeFileProvider.Instance;
        private LiquidParser _parser = new LiquidParser();
        private LiquidTemplateOptions _templateOptions = new LiquidTemplateOptions();
        private TextEncoder _textEncoder = HtmlEncoder.Default;
        private FormatAssetUrlDelegate _assetUrlFormatter = FormatAssetUrl;

        public ILiquidThemeFileProvider FileProvider
        {
            get => _fileProvider;
            set => _fileProvider = value ?? throw new ArgumentNullException(nameof(value));
        }
        public LiquidParser Parser
        {
            get => _parser;
            set => _parser = value ?? throw new ArgumentNullException(nameof(value));
        }
        public LiquidTemplateOptions TemplateOptions
        {
            get => _templateOptions;
            set => _templateOptions = value ?? throw new ArgumentNullException(nameof(value));
        }
        public TextEncoder TextEncoder
        {
            get => _textEncoder;
            set => _textEncoder = value ?? throw new ArgumentNullException(nameof(value));
        }
        public FormatAssetUrlDelegate AssetUrlFormatter
        {
            get => _assetUrlFormatter;
            set => _assetUrlFormatter = value ?? throw new ArgumentNullException(nameof(value));
        }
        private static string FormatAssetUrl(string theme, string url, string version)
        {
            return $"/themes/{theme}/assets/{url}?v={version}";
        }
    }
}